<?php

namespace app\common\exception;

use think\exception\Handle;
use think\exception\HttpException;
use think\exception\ValidateException;
use think\Response;
use Throwable;

class ExceptionHandle extends Handle
{
    public function render($request, Throwable $e): Response
    {
        // 正式环境，企业微信通风报信
        if (isProd()) {
            $message = 'File: '.$e->getFile().PHP_EOL.'Line: '.$e->getLine().PHP_EOL.'Message: '.$e->getMessage();
            $md5 = md5($message);
            $lock = cache($md5);
            if (!$lock) {
                $work = new \app\common\model\Work;
                $work->exceptionNotify($message);
                cache($md5, 1, 120);
            }
        }

        // 其他错误交给系统处理
        return parent::render($request, $e);
    }
}
